package com.web.music.portal.mvc;

import java.beans.PropertyEditorSupport;

import com.web.music.interfaces.PersonService;
import com.web.music.model.Person;

public class PersonPropertyEditor extends PropertyEditorSupport {
	
	private PersonService personService;
	
	public PersonPropertyEditor(PersonService personService) {
		super();
		this.personService = personService;
	}
	@Override
	public String getAsText() {
		if (getValue() != null && getValue() instanceof Person) {
			Person p = (Person) getValue();
			return p.getSurname();
		}
		return super.getAsText();
	}

	@Override
	public void setAsText(String arg0) throws IllegalArgumentException {
		Long id = new Long(arg0);
		setValue(personService.getById(id));
	}
	
	

}
